Skip to content

Every step of PR work knows the other repositories its change reaches - #979

Merged
coderhelm[bot] merged 15 commits into
mainfrom
feat/installation-contract-index
Dec 5, 2026
Merged

coderhelm[bot] merged 15 commits into
mainfrom
feat/installation-contract-index

Conversation

@nambok

@nambok nambok commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

PR work now knows the whole installation the way a senior developer does. An installation-level contract index, built with each repository's code graph and refreshed on every push, records per repository what it exposes and what it uses: HTTP endpoints, GraphQL root fields, events and queue messages, packages and the symbols imported from them, and environment variables. Every pass of PR work reads it. Planning, coding, fix and CI rounds, review and the pull request itself all know which other repositories a change reaches. A contract change with known consumers never ships without either changing them or an explicit compatibility note. Reading stays unrestricted. Nothing written into a public repository names a private one or copies its code, on any surface.

Builds on #973 (repo_reach's read tools and leak check), now on main.

Changes

  • common::contracts (new): the index.
    • Pattern extraction, no model:
      • routes in Express, Fastify, Hono, FastAPI, Flask, axum, actix, Go, Spring and Next.js file routes, and client calls;
      • GraphQL Query, Mutation and Subscription fields, and the operations that use them;
      • publish and subscribe topics;
      • package.json, Cargo.toml, pyproject.toml, go.mod and requirements names and dependencies;
      • JS/TS, Python and Rust imports from installation packages;
      • environment reads in code and settings in config and infrastructure.
    • One record per repository. Every record of a team sits in one partition, read in one query and kept in memory for ten minutes.
    • Index::links works out consumers and producers in memory. Index::breaks finds a contract a patch removes or renames while another repository still uses it.
    • The find_consumers tool and its prompt.
  • Refreshed with the code graph: code_graph::refresh_contracts runs in the same index pass. A first build reads every file. A push replaces only the changed files' entries. A newly exposed package has its dependents read again (at most 10).
  • passes::xrepo (new): what each step reads. It rides in RepoGraphs::load_map next to the app map, so every pass that already reads code gets it.
    • Planner: its first message lists what the likely files reach. A plan whose files carry contracts another repository uses goes back once, unless it adds a ## owner/repo group for each consumer (the existing multi-repository plan) or a ## Compatibility section.
    • Coder, fix rounds and CI rounds: the consumers' own lines go into the first message (at most six excerpts). Person-asked rounds now load the maps too.
    • Reviewer:
      • It sees every contract the change touches that another repository uses.
      • A removed or renamed contract a consumer still uses is a required, blocking finding that cites the consumer.
      • Its code graph now covers the team's other repositories (previously it was opened with none).
    • Pull request: a body that touches contracts others use, with neither those repositories in the run nor a compatibility section, gets one. Removed contracts are marked breaking.
  • Every loop: find_consumers is offered beside the read tools, and the prompt says to ask it before changing or explaining a contract.
  • Privacy on every surface, one leak check (repo_reach::leak / redact):
    • Private reads by work posting to a public repository are kept per installation and target (repo_reach::note_private), including what the index showed the run.
    • A write tool whose input copies a private line, or names a private repository or a path read there, is refused with the reason (agent::reach::Exec).
    • Every POST, PATCH and PUT the GitHub client sends has private content taken out of its title, body, message and inline comment bodies before it reaches a public repository (clients::github::public_payload). That covers pull requests, commits, comments, reviews, dismissals and releases.
    • A repository known only by name is matched by owner/name, so common words stay readable.
    • Private-to-private work references freely.
  • Incident xt_contract_change_reaches_every_consumer (case and page), the new caches listed in bm, and docs in code-map.md.

Cost bounds:

  • Extraction:
    • File size: 256 KB at most.
    • Files per pass: 6,000 at most.
    • Entries: 80 per file and 4,000 per repository. Environment reads, then imported symbols, are dropped first.
    • Stored record: under 300 KB gzipped.
  • Reads: one query per team every ten minutes.
  • Answers: 40 links each.
  • Prompt sections: the coder gets 12,000 characters, the planner and the reviewer 4,000 each.
  • First reads of uncovered repositories: 3 queued per step.

Verification

  • cargo fmt --all --check and rustfmt --check on the incidents: clean.
  • cargo clippy -p common -p worker -p gateway --all-targets -- -D warnings: clean.
  • cargo test -p common -p worker -p gateway, after merging main: common 3,337 passed, gateway 1,363 passed, worker 2,958 passed, none failed.
  • brand_spelling.py and domain_examples.py: clean.
  • New tests:
    • Extraction and matching: every kind is extracted, and paths normalize and match (contracts::tests).
    • Records: incremental and bounded.
    • Breaks: a removed route with a consumer is a break; a rewrite that keeps it is not.
    • Compatibility section: it never names a private repository in a public one.
    • Leak check: the public-surface ledger and a public write that copies a private repository (repo_reach, agent::reach).
    • The xt incident covers:
      • the planner's gap and send-back;
      • the required finding, with and without private names;
      • the ship-time compatibility note, and its place before the pull request opens;
      • the source checks that every pass uses the index;
      • a scan that no prompt or graph registry limits PR work to one repository;
      • public payloads redacted per installation, with private repositories untouched.

nambok and others added 12 commits December 4, 2026 14:55
A check red on the pull request and green on the base first gets the mode
diagnosis: files the pull request changes are compared with the merge
base, and a mode CoderHelm's commits dropped is put back in one commit
with no model round; what can't be put back yet is CoderHelm's own
problem, alerted and retried. restore_file restores the mode with the
bytes, set_mode sets a file's executable bit (refusing links and
submodules), and a sandbox chmod says it never reaches the commit. The
repair sweep compares with the base, reads failed runs first and resumes
a run that ended on red CI.

Every worker loop with tools gets list_repos, read_repo_file and
search_repo over the team's installation, with the prompt; Chat's prompt
says the same. Text claiming CoderHelm can't see or confirm something is
rejected unless a tool returned a refusal it names.
…nd stuck repairs

The guard reads first-person claims only (I, we, CoderHelm, the agent):
sentences about the code or the product pass untouched. It reads prose
lines only: fenced code, data lines and structured output are never
read or edited. A look-first retry that fails or runs out of time keeps
the first answer and the history it came from. The claim check is part
of person_text itself.

A stuck mode repair retries while the tries put more back; after three
tries with no progress it stops, records why once as its own problem,
and the run waits on CI. A sweep whose branch moved gives its claim
back. A failed installation read is kept for seconds, not minutes, and a
comparison cut at one page says so.
…itories

Reading stays allowed everywhere. Visibility comes from the
installation's repository list; a repository it doesn't name as public
counts as private. A reply going to a public repository keeps every
private read of its turn and is checked before sending: no verbatim line
or code from those reads, no private repository name or path. It is asked
for its conclusion in plain words, and what still carries private
content is taken out, in prose and structured replies alike, never
replaced by a claim that it can't see the code.
An installation contract index, built with each repository's code graph
and refreshed on every push, records per repository the endpoints,
GraphQL fields, events, packages, imported symbols and environment
variables it exposes and uses (common::contracts). Every pass of PR work
reads it (passes::xrepo): the planner sees the consumers and a plan that
ignores them goes back; the coder and every round through it start with
the consumers' lines; the reviewer raises a removed contract a consumer
still uses as a required finding; a pull request touching contracts
others use carries a compatibility section unless it changes them. Every
loop has find_consumers.

Reading stays unrestricted. Private reads by work posting to a public
repository are kept per installation; a write tool copying them is
refused, and every text the GitHub client writes there has them taken out
by the same leak check. Incident xt holds the invariants.
@nambok nambok added the ch-review CoderHelm reviews this pull request label Dec 5, 2026
coderhelm[bot]

This comment was marked as outdated.

…gets its contracts read, and private reads outlive the process

- A package renamed in its manifest counts as removed; an endpoint moved
  to another HTTP method is a break, not a rewrite. Removals are matched
  by the patch's removed text, not by the index's line numbers, which may
  come from another commit than the pull request's base.
- Repositories with no record, and dependents of a newly exposed
  package, get a contracts-only read with its own queue mark, which never
  reads the code graph's status: a repository whose graph is built is
  read too. Its graph and build status are left as they are.
- What work posting to a public repository reads in private ones is also
  kept in a short-lived store item per installation, public repository
  and run. Every model loop waits for it to be stored, and the GitHub
  client reads it back before each write, so a write in a later
  invocation is held to an earlier read.
- An unreadable index record is logged; per-step index logs are debug.
coderhelm[bot]

This comment was marked as outdated.

@coderhelm
coderhelm Bot dismissed their stale review December 5, 2026 06:46

Superseded by CoderHelm's latest review

When the installation's listing can't be read, or doesn't name a
repository, that repository counts as private when it was read and as
public when it is written to (reach::Visibility). Only a target the
listing names, and not as public, is private. The model loops, the
contract index view and so the GitHub client's held writes all decide
through it, and a loop whose listing failed still keeps its reads under
the team's installation. Reading is never limited by it.

@coderhelm coderhelm Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved with notes da42726 (merged)

) -> Result<(), String> {
use aws_sdk_dynamodb::primitives::Blob;
use aws_sdk_dynamodb::types::AttributeValue;
dynamo

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Suggestion: Record write is an unconditional read-modify-write (hardening)

save_record does a plain put_item of the whole record. refresh_contracts in code_graph.rs (around line 970) loads the stored record, replaces only the pushed files' entries and saves it back. If two index passes for the same repository overlap, the later write is based on the older record. The earlier pass's changed files then revert to their previous entries, and nothing re-reads them until they change again. I couldn't tell whether index passes are serialized per repository, so this is an unconfirmed concern. A conditional write on the stored commit or updated_at, with a re-read on conflict, would close it. The existing graph item writes follow the same unlocked pattern, so this is hardening, not a regression.

// What the patch removes, by its text: the index's line numbers
// may come from another commit than the pull request's base.
let removed: Vec<String> = removed.into_iter().map(|(_, t)| t).collect();
let links = self.links(repo, std::slice::from_ref(path));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Suggestion: breaks can miss a consumer once the file's links pass the 40-link cap (correctness, not verified)

breaks takes its consumers from self.links(repo, [path]), which sorts by direction, then environment, then kind, and truncates to MAX_LINKS (40). For a file with many contracts, such as a large router or a manifest with many dependents, consumer links for a removed contract can fall past the cap. That break is then silently not reported. A small internal variant of links without the cap, or a cap applied only after breaks has matched each entry, would avoid it.

This blocks: breaks is the change's core data-loss path: a removed contract with a used consumer is silently not reported, defeating the stated goal, shown by the cap truncation

let body = crate::app_map::gzip(&serde_json::to_vec(&new).unwrap_or_default());
let expires = chrono::Utc::now().timestamp() + LEDGER_KEEP_SECS as i64;
let run = if run.is_empty() { "step" } else { run }.to_string();
let handle = rt.spawn(async move {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Suggestion: A failed refill is retried on every public write (hardening, not verified)

In refill, the Err(e) arm only logs a WARNING. REFILLED is set only on success, so during a store outage every POST, PATCH or PUT to a public repository runs a fresh DynamoDB query and logs again. The store is hit on each write and the log fills up. Also, query orders by sk (RUN#{run}#...), not by time. If more than REFILL_MAX_ITEMS batches exist for one target, the batches dropped are not the oldest ones. Both are edge cases, and the process's own in-memory reads are still checked.

@coderhelm
coderhelm Bot dismissed their stale review December 5, 2026 08:00

Superseded by CoderHelm's latest review

@coderhelm

coderhelm Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

💚 Post-merge health check passed: the deploy of 4e0b295 completed and stayed green for the full 15-minute watch window (no new failures vs. the pre-merge baseline).
Auto-merge

  • ✅ CoderHelm approved
  • ✅ CI green
    The rest is in the pull request description.

@coderhelm
coderhelm Bot merged commit 4e0b295 into main Dec 5, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ch-review CoderHelm reviews this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant